﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace aier.wx.nosql.redis
{
    public class RedisTestDal
    {
        public RedisClientManager redisClientManager { get; set; }

        public void Set(string key, string value)
        {
            redisClientManager.UseRedisClient(action =>
            {
                action.Remove(key);
                action.Set<string>(key, value);
            });
        }
        public string Get(string key)
        {
            return redisClientManager.UseRedisClient<string>(action =>
            {
                return action.Get<string>(key);
            });
        }

        public void Set<T>(string key, T value)
        {
            redisClientManager.UseRedisClient(action =>
            {
                action.Remove(key);
                action.Set<T>(key, value, TimeSpan.FromMinutes(5));
            });
        }

        public void Set<T>(string key, T value, TimeSpan ts)
        {
            redisClientManager.UseRedisClient(action =>
            {
                action.Remove(key);
                action.Set<T>(key, value, ts);
            });
        }

        public T Get<T>(string key)
        {
            return redisClientManager.UseRedisClient<T>(action =>
            {
                return action.Get<T>(key);
            });
        }


    }
}
